[数据结构机考题目]生成一个任意的单链表,并对单链表进行排序

来源:百度知道 编辑:UC知道 时间:2024/06/15 22:01:20
用C/C++写...可以运行的.完整的代码

还可以追加100分

非常感谢
有两位大侠

分给谁啊

#include <stdio.h>
#include <stdlib.h>

struct lnode
{
int data;
struct lnode *next;
} ;

struct lnode* creatlnode(struct lnode *l,int n);

void printlnode(struct lnode *l);

/**********************************************
建表
***********************************************/
struct lnode* creatlnode(struct lnode *l,int n)
{
struct lnode *p,*h;
int i,x;
l=(struct lnode*) malloc (sizeof(struct lnode));
p=l;

for(i=1;i<=n;i++)
{
h=(struct lnode*) malloc (sizeof(struct lnode));
scanf("%d",&x);
h->data=x;
h->next=NULL;
p->next=h;
p=p->next;
}
return l;
}

/****************************************************
输出
***********************************